package com.lpb.spring.test.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName JdkProxy
 * @Description TODO
 * @date 2022/12/8 01:24
 * @Version 1.0
 * @authoe linpengbo
 */
public class CglibProxy implements MethodInterceptor {

    private Object target;

    public CglibProxy(Object target){
        this.target=target;
    }


    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("这里是cglib动态代理before...");
        Object invoke = method.invoke(target, objects);
        System.out.println("这里是cglib动态代理after...");
        System.out.println(o.getClass().getName());
        return invoke;
    }
}
